<template>
  <div class="index">
    <!--head-->
    <div class="role-head">
      <p class="role-head-title"><i class="icon iconfont icon-shezhi"></i>系统参数</p>
      <div class="role-head-operation">
        <span class="role-head-operation-items" v-if="sysparamsRead" @click="selectShow"><i class="icon iconfont icon-chaxun"></i><span style="display:block;float:left">查询</span></span>
        <span class="role-head-operation-items" v-if="sysparamsAdd" @click="toAdd"><i class="icon iconfont icon-xinzeng"></i><span style="display:block;float:left">新增</span></span>
        <span class="role-head-operation-items"><a style="color:#fff;" href="javascript:history.go(-1)"><span style="display:block;float:left;font-size:16px;">返回</span><i class="icon iconfont icon-jinru"></i></a></span>
      </div>
    </div>
    <!--head end-->
    <!--select-->
    <div class="role-select on">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form label-position="left" label-width="80px" class="aaa">
            <el-form-item label="参数名称" class="rolelabel">
              <el-input class="role-select-ipt" v-model="select.paramName"></el-input>
            </el-form-item>
          </el-form>
        </el-col>
        <!-- <el-col :span="12">
          <el-form label-position="left" label-width="80px">
            <el-form-item label="每页行数" class="rolelabel">
              <el-input class="role-select-ipt" type="number" v-model="select.pageSize"></el-input>
            </el-form-item>
          </el-form>
        </el-col> -->
        <el-col :span="6" :offset="6">
            <el-button @click="selectHide" class="colse">关    闭</el-button>
            <el-button class="select-submit" @click="getSystem">查    询</el-button>
        </el-col>
      </el-row>      
    </div>
    <!--select end-->
    <!--table-->
    <div class="role-table">
      <table id="role-table">
          <tbody class="role-table-title">
            <td>参数名称</td>
            <td>参数值</td>
            <td>参数模块</td>
            <td>描述</td>
            <td style="text-indent:18px;">操作</td>
          </tbody>
          <tr v-if="empty">
            <td class="empty" colspan="5">暂无数据</td>
          </tr>
          <tr v-else v-for="item in list" :key="item.paramBh">
            <td>{{item.paramName}}</td>
            <td>{{item.paramVal}}</td>
            <td>{{item.paramMode}}</td>
            <td>{{item.description}}</td>
            <td>
              <div class="role-table-operation">
                <i class="icon iconfont icon-bianji" v-if="sysparamsEdit" @click="getPerSystem(item.paramBh)" title="编辑"></i>
                <i class="icon iconfont icon-shanchu" v-if="sysparamsDelete" @click="toDelete(item.paramBh)" title="删除"></i>
              </div>
            </td>
          </tr>
      </table>
    </div>
    <!--table end-->
    <!--分页-->
    <el-pagination
      @current-change="handleCurrentChange"
      :current-page.sync="currentPage"
      :page-size="13"
      layout="prev, pager, next, jumper"
      :total="parseInt(total)"><!--因为这里:total期望的值是Number类型，但是vue返回的是String类型，所以要parseInt()转换类型-->
    </el-pagination>
    <!--分页 end-->
    <!--roleGrant-->
    <roleGrant ref="model" v-if="show" :perlist="perlist"></roleGrant>
    <!--roleGrant end-->
    <!--roleAdd-->
    <roleAdd ref="Add" v-if="Addshow"></roleAdd>
    <!--roleAdd end-->
  </div>
</template>

<script>
import roleGrant from "./../components/systemEdit";
import roleAdd from "./../components/systemAdd";
import axios from "axios";
export default {
  name: "system",
  components: {
    roleGrant,
    roleAdd,
  },
  data() {
    return {
      currentPage: 1,
      total: '',
      show: false,
      Addshow: false,
      empty: false,
      sysparamsRead: '',
      sysparamsAdd: '',
      sysparamsEdit: '',
      sysparamsDelete: '',
      select: {
        paramName: "", //参数名称
        currentPage: "", //当前页
        pageSize: 13, //每页行数
        sortby: "", //排序列
        order: "asc" //排序方式正序：asc，倒序：desc
      },
      list: [], //全部信息
      perlist: {} //个人信息
    };
  },
  mounted: function() {
    this.$nextTick(() => {
      //防止在登陆页没有登陆时候直接手动改变url访问
      this.initPage();
      //调用全局方法 设置index高度
      this.indexHeight();
      //表格高度
      $(".role-table").height($(window).height() - 330 + "px");
      //
      this.getSystem();
      //调用全局方法根据权限值显示对应信息
      this.grantType();
    });
  },
  methods: {
    handleCurrentChange(val) {
      this.currentPage = val;
      axios
        .get(sysparamsURL, {
          headers: { Authorization: appDB.get("userInfo").token },
          params: {
            currentPage:this.currentPage,
            pageSize: 13
          }
        })
        .then(res => {
          let d = res.data;
          if (d.resultCode == 0) {
            this.total = d.record.totalPage;
            if (d.record.rows.length > 0) {
              this.list = d.record.rows;
              this.empty = false;
            } else {
              this.empty = true;
            }
          } else {
            layer.msg(d.msg);
          }
        })
        .catch(error => {
          layer.msg("网络错误");
        });
    },
    //查条件hide
    selectShow() {
      $(".role-select").removeClass("on");
    },
    //查询条件hide
    selectHide() {
      $(".role-select").addClass("on");
      this.select.paramName = "";
      this.select.pageSize = 13;
      this.getSystem();
    },
    //获取全部系统参数
    getSystem() {
      axios
        .get(sysparamsURL, {
          headers: { Authorization: appDB.get("userInfo").token },
          params: this.select
        })
        .then(res => {
          let d = res.data;
          if (d.resultCode == 0) {
            this.total = d.record.totalPage;
            if (d.record.rows.length > 0) {
              this.list = d.record.rows;
              this.empty = false;
            } else {
              this.empty = true;
            }
          } else {
            layer.msg(d.msg);
          }
        })
        .catch(error => {
          layer.msg("网络错误");
        });
    },
    //获取单个系统参数
    getPerSystem(paramBh) {
      axios
        .get(sysparamsURL + '/' + paramBh, {
          headers: { Authorization: appDB.get("userInfo").token }
        })
        .then(res => {
          let d = res.data;
          if (d.resultCode == 0) {
            this.perlist = d.record;
            this.toEdit();
          } else {
            layer.msg(d.msg);
          }
        })
        .catch(error => {
          layer.msg("网络错误");
        });
    },
    //编辑
    toEdit() {
      this.show = true;
      this.$nextTick(() => {
        let that = this;
        layer.open({
          type: 1,
          shadeClose: true,
          title: "编辑参数",
          skin: "layui-layer-rim", //加上边框
          area: ["600px", "500px"], //宽高
          content: $(this.$refs.model.$el),
          end: function() {
            that.show = false;
          }
        });
      });
    },
    //新增
    toAdd() {
      this.Addshow = true;
      this.$nextTick(() => {
        let that = this;
        layer.open({
          type: 1,
          shadeClose: true,
          title: "新增参数",
          skin: "layui-layer-rim", //加上边框
          area: ["600px", "500px"], //宽高
          content: $(this.$refs.Add.$el),
          end: function() {
            that.Addshow = false;
          }
        });
      });
    },
    //dedlete
    toDelete(paramBh) {
      axios
        .delete(sysparamsURL + '/' + paramBh, {
          headers: { Authorization: appDB.get("userInfo").token }
        })
        .then(res => {
          let d = res.data;
          if (d.resultCode == 0) {
            this.getSystem();
          } else {
            layer.msg(d.msg);
          }
        })
        .catch(error => {
          layer.msg("网络错误");
        });
    }
  }
};
</script>

<style scoped>
@import "../assets/css/elementUI.css";
.el-pagination{
  margin-top: 15px;
}
.role-head {
  width: 100%;
  float: left;
  color: #fff;
  margin: 70px 0 20px 0;
}
.role-head-title {
  float: left;
  font-size: 16px;
  line-height: 30px;
}
.icon-shezhi {
  font-size: 20px;
  margin-right: 8px;
  float: left;
}
.role-head-operation {
  /* width: 258px; */
  float: right;
}
.role-head-operation-items {
  height: 18px;
  line-height: 18px;
  padding: 0 20px;
  display: inline-block;
  cursor: pointer;
  border-right: 1px solid #fff;
  float: left;
}
.role-head-operation-items:last-child {
  float: left;
  border-right: 0;
  font-size: 16px;
  padding-right: 0;
}
.icon-chaxun {
  display: inline-block;
  margin-right: 4px;
  float: left;
}
.icon-xinzeng {
  display: inline-block;
  margin-right: 4px;
  font-size: 18px;
  float: left;
}
.icon-jinru {
  color: #35c126;
  font-size: 26px;
  display: inline-block;
}
.role-table {
  width: 100%;
  float: left;
  background: #fff;
  overflow-y: auto;
}
#role-table {
  width: 100%;
  border: 0;
  background: #fff;
  float: left;
}
#role-table tr td {
  padding: 12px 15px;
  border: 1px solid #cbcbcb;
}
#role-table tr:hover {
  background: #f0f0f0;
}
.role-table-title {
  width: 100%;
  background: #0a456f;
  color: #fff;
}
.role-table-title td {
  padding: 12px 15px;
  border-right: 1px solid #012842;
  border-bottom: 1px solid #cbcbcb;
}
.role-table-operation {
  display: flex;
  justify-content: space-around;
}
.role-table-operation i {
  color: #5594d1;
  font-size: 18px;
  cursor: pointer;
}
.role-select {
  width: 100%;
  height: 146px;
  padding: 20px 4%;
  overflow: hidden;
  float: left;
  background: #14466a;
  margin-bottom: 20px;
  transition: all ease-in-out 0.5s;
}
.role-select.on {
  width: 100%;
  height: 0;
  padding: 0 4%;
  background: #14466a;
  margin-bottom: 0;
}
.colse {
  border-radius: 30px;
  padding: 8px 40px;
  background: none;
  border: 1px solid #367fb6;
  color: #fff;
}
.select-submit {
  border-radius: 30px;
  padding: 8px 40px;
  background: #39b423;
  border: 1px solid #39b423;
  color: #fff;
}
.layui-layer-title {
  color: #000;
  font-size: 16px;
}
</style>

